package com.lrs.java.dataStructure.simpleSort;

class BubbleArray {

	private long[] arr;
	private int nElems;
	public void insert(long value) {
		arr[nElems] = value;
		nElems++;
	}

	public BubbleArray(int capacity) {
		arr = new long[capacity];
	}
	
	private void swap(int firstIdx, int secondIdx) {
		long temp = arr[firstIdx];
		arr[firstIdx] = arr[secondIdx];
		arr[secondIdx] = temp;
	}

	public void bubbleSort() {
		int out, in;
		//ordered by asc
		for(out=nElems-1; out>0; out--) {
			for(in=0;in<out;in++) {
				if(arr[in] > arr[in+1]) {
					swap(in, in+1);
				}
			}
		}
	}
	public void display() {
		for(int i=0; i<nElems; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
	}
}


class BubbleSortApp {
	public static void main(String[] args) {
		BubbleArray bubble = new BubbleArray(10);
		
		bubble.insert(3);
		bubble.insert(2);
		bubble.insert(1);
		
		bubble.display();
		
		bubble.bubbleSort();
		
		bubble.display();
		
		
	}
}